package net.northcoding.fresh.token;
// @Author Diamond - Administrator
// @Date 2023/12/8 10:26:16

import java.util.HashMap;

public class Token {
    public static final HashMap<String, TokenType> types = new HashMap<>();

    static {
        types.put("+", TokenType.PLUS);
        types.put("-", TokenType.SUB);
        types.put("*", TokenType.MUL);
        types.put("/", TokenType.DIV);
        types.put("(", TokenType.OP);
        types.put(")", TokenType.CP);
        types.put("!", TokenType.EX);
        types.put("[", TokenType.OB);
        types.put("]", TokenType.CB);
        types.put("{", TokenType.OC);
        types.put("}", TokenType.CC);
        types.put("#", TokenType.POU);
        types.put("=", TokenType.EQU);
        types.put("?", TokenType.QT);
        types.put("<", TokenType.LESS);
        types.put(">", TokenType.MORE);
        types.put(".", TokenType.DOT);
        types.put(";", TokenType.SEM);
        types.put("%", TokenType.PERCENT);
    }

    private String literal;
    private TokenType type;
    public Token(String literal, TokenType type) {
        this.literal = literal;
        this.type = type;
    }

    public Token() {
    }

    public static Token createToken(String literal, TokenType type) {
        return new Token(literal, type);
    }

    public String getLiteral() {
        return literal;
    }

    public void setLiteral(String literal) {
        this.literal = literal;
    }

    public TokenType getType() {
        return type;
    }

    public void setType(TokenType type) {
        this.type = type;
    }

    public enum TokenType {
        DIV,         // /
        INT,         // 123
        MUL,         // *
        PERCENT,     // %
        PLUS,        // +
        SUB,         // -
        EQU,         // =
        MORE,        // >
        LESS,        // <
        OB,          // [
        CB,          // ]
        OP,          // (
        CP,          // )
        OC,          // {
        CC,          // }
        DOT,         // .
        REF,         // |
        POU,         // #
        QT,          // ?
        EX,          // !
        IDENTITY,    // xxx
        STRING,      // "1ms"
        SEM,         // ;
        EOF,         // End of file
        ILL,         // [unreadable]
        KEYWORD      // return
    }
}
